﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using Might.Infrastructure.Annotations.Graphics;

namespace Might.GraphicsEditor.GraphicsObjects {
    /// <summary>
    /// Class representation for simple ellipse
    /// </summary>
    public class LeafBitmap : GraphicsComponent {
        internal Path Path { get; set; }
        internal RectangleGeometry rect;

        /// <summary>
        /// Public constructor for simple ellipse
        /// </summary>
        public LeafBitmap(IGraphicsItem ga) {
            this.ga = ga;
            rect = new RectangleGeometry {
                Rect = new Rect(0, 0, 100, 100)
            };

            Path = new Path {
                StrokeLineJoin = PenLineJoin.Bevel,
                Stretch = Stretch.Fill,
                Data = rect
            };
            Content = Path;

            UpdateShape();

            this.ga.Changed += GaGraphicsPrimitiveChanged;
        }

        protected override void UpdateShape() {
            base.UpdateShape();
            var g = ga as IGraphicsBitmap;
            if (g == null) {
                throw new NullReferenceException("Updating Null anotation");
            }
            if (((ImageBrush) Fill).ImageSource != g.Image) {
                Fill = new ImageBrush {ImageSource = g.Image};
            }
        }

        /// <summary>
        /// Color of the filled area
        /// </summary>
        public Brush Fill {
            get { return Path.Fill; }
            set { Path.Fill = value; }
        }
    }
}
